package com.imust.test;

import com.imust.test.manager.Signup;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Main {
    private static Check ll =null;
    static JFrame frame = new JFrame("数据库管理系统");
    public static void main(String[] args) {
        // 创建顶层容器 JFrame

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置关闭操作
        // 设置顶层容器大小
        frame.setSize(400, 500);
        // 将窗口定位在屏幕的中央位置
        frame.setLocationRelativeTo(null);
        frame.setResizable(false);
        frame.setUndecorated(true);
        BorderLayout border_layout = new BorderLayout();
        frame.setLayout(border_layout);
        JPanel panel_north = CreatePanel.CreateNorthPanel(frame);
        frame.add(panel_north, BorderLayout.PAGE_START);
        // 2.2、创建并加入中部面板
        JPanel panel_center = CreatePanel.CrateCenterPanel(frame);
        frame.add(panel_center, BorderLayout.CENTER);
        // 2.4、创建并加入底部面板
        JPanel panel_south = CreatePanel.CreateSouthPanel();
        frame.add(panel_south, BorderLayout.PAGE_END);
        // 设置顶层容器可见
        frame.setVisible(true);

    }
    public static void closemain(){
        frame.dispose();
    }

    public static class CreatePanel {
        static JTextField text = new JTextField();
        public static JPanel CreateNorthPanel(JFrame frame){
            // 1、创建一个JPanel顶部面板
            JPanel panel=new JPanel();
            // 取消面板内默认布局
            panel.setLayout(null);
            // 设置顶部面板尺寸
            panel.setPreferredSize(new Dimension(0, 140));
            // 1.1、向顶部面板添加背景图片
            ImageIcon image=new ImageIcon("images/background.jpg");
            JLabel background=new JLabel(image);
            // 设置背景图片的位置及尺寸
            background.setBounds(0,0,400,image.getIconHeight());
            JLabel text = new JLabel("欢迎使用数据库管理系统");
            text.setBounds(50,70,30,20);
            panel.add(background);
            panel.add(text);
            return panel;
        }
        public static JPanel CrateCenterPanel(JFrame frame){
            // 1、创建一个JPanel中部面板
            JPanel panel = new JPanel();
            panel.setLayout(null);
            panel.setPreferredSize(new Dimension(400,160));

            text.setBounds(115,36,175,25);
            panel.add(text);
            // 1.1 创建一个JcomboBox下拉框组件，并初始化QQ账号
            String str []= {"2367219043"};
            JComboBox<Object> jcoCenter = new JComboBox<Object>(str);

            panel.add(jcoCenter);
            // 设置下拉框可编辑

            jcoCenter.setEditable(true);
            jcoCenter.setBounds(115, 60, 175, 25);
            // 设置下拉框内容字体
            jcoCenter.setFont(new Font("Calibri ",0,13));
            // 1.2、创建一个JPasswordField密码框组件
            JPasswordField jpaCenter = new JPasswordField();
            // 设置密码框面板为FlowLayout流失布局
            jpaCenter.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0));
            jpaCenter.setBounds(115, 84, 176, 25);
            jpaCenter.setPreferredSize(new Dimension(185,25));
            jpaCenter.setFont(new Font("Calibri ",0,13));
            panel.add(jpaCenter);
            // 1.3、创建ImageIcon小键盘图标组件，并加入到密码框组件中
            ImageIcon image = new ImageIcon("images/eye_close.jpg");
            JButton kb = new JButton(image);
            kb.setPreferredSize(new Dimension(22,20));
            kb.setBorderPainted(false);
            jpaCenter.add(kb);
                kb.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        jpaCenter.putClientProperty("JTextField.trailingComponent", kb);//设置隐藏按钮显示，未使用FlatLightLaf则不需要
                        jpaCenter.setEchoChar((char) 0);//设置密码显示
                        kb.setVisible(false);
                        ImageIcon image1 = new ImageIcon("images/eye_open.jpg");
                        JButton kb_1 = new JButton(image1);
                        kb_1.setPreferredSize(new Dimension(22, 20));
                        kb_1.setBorderPainted(false);
                        jpaCenter.add(kb_1);

                    }
                });
            // 1.4、创建两个JCheckBox多选框组件
            JCheckBox jch1 = new JCheckBox("记住密码");
            // 设置选中时不显示边框
            jch1.setFocusPainted(false);
            jch1.setFont(new Font("微软雅黑",0,13));
            jch1.setBounds(125, 125, 80, 20);
            panel.add(jch1);
            JCheckBox jch2 = new JCheckBox("自动登录");
            jch2.setFocusPainted(false);
            jch2.setFont(new Font("微软雅黑",0,13));
            jch2.setBounds(220, 125, 80, 20);
            panel.add(jch2);
            ll = new Check(jcoCenter, jpaCenter, frame);
            return panel;
        }
        public static String Text(){
            String str = text.getText();
            return str;
        }
        public static JPanel CreateSouthPanel() {
            // 1、创建一个JPanel底部面板
            JPanel panel = new JPanel();
            panel.setPreferredSize(new Dimension(0, 200));
            panel.setLayout(null);
            // 1.2、创建底部中间登录图标组件
            JButton btn = new JButton("登  录");
            btn.setFont(new Font("微软雅黑", 0, 13));
            btn.setBounds(165, 0, 80, 40);
            btn.addActionListener(ll);

            JButton btn_1 = new JButton("注  册");
            btn_1.setFont(new Font("微软雅黑", 0, 13));
            btn_1.setBounds(165, 55, 80, 40);
            btn_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Signup.signup();
                }
            });

            JButton btn_2 = new JButton("退  出");
            btn_2.setFont(new Font("微软雅黑", 0, 13));
            btn_2.setBounds(165, 110, 80, 40);
            btn_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }
            });

            panel.add(btn);
            panel.add(btn_1);
            panel.add(btn_2);
            return panel;
        }
    }

}
